﻿using AutoMapper;
using MediatR;
using ProductionManagement.Application.Command.SendWorkersForQualityInspectionCommand;
using ProductionManagement.Domain.ProductionDomain;
using ProductionManagement.Infrstructre.lnterface;

namespace ProductionManagement.Application.CommandHandler.SendWorkersForQualityInspectionCommandHandlers
{
    public class SendWorkersForQualityInspectionCreateCommandHandlers : IRequestHandler<SendWorkersForQualityInspectionCreateCommand, int>
    {

        private readonly IMapper mapper;
        protected readonly ISendWorkersForQualityInspectionRepository repository;

        public SendWorkersForQualityInspectionCreateCommandHandlers(IMapper mapper, ISendWorkersForQualityInspectionRepository repository)
        {
            this.mapper = mapper;
            this.repository = repository;
        }

        public async Task<int> Handle(SendWorkersForQualityInspectionCreateCommand request, CancellationToken cancellationToken)
        {
            request.dtos.SWFQICode = Guid.NewGuid().ToString();
            return await repository.AddAsync(mapper.Map<SendWorkersForQualityInspection>(request.dtos));
        }
    }
}
